package com.shangsheng.dao.impl;

import com.shangsheng.dao.AbstractDao;
import com.shangsheng.dao.UserProfileDao;
import com.shangsheng.entity.UserProfile;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserProfileDaoImpl extends AbstractDao<Integer,UserProfile> implements UserProfileDao {

    @Override
    public List<UserProfile> findAll() {
        Criteria criteria = createEntityCriteria();
        criteria.addOrder(Order.asc("type"));
        return criteria.list();
    }

    @Override
    public UserProfile findById(int id) {
        return getByKey(id);
    }

    @Override
    public UserProfile findByType(String type) {
        Criteria criteria=createEntityCriteria();
        criteria.addOrder(Order.asc(type));
        return (UserProfile) criteria.uniqueResult();
    }
}
